package com.sm.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sm.dao.DataCloudLibraryCategoryMapper;
import com.sm.dao.DataCloudLibraryMapper;
import com.sm.model.DataCloudLibrary;
import com.sm.model.DataCloudLibraryCategory;
import com.sm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataCloudLibraryService {

    @Autowired
    private DataCloudLibraryMapper dataCloudLibraryMapper;
    @Autowired
    private DataCloudLibraryCategoryMapper dataCloudLibraryCategoryMapper;

    //分页查询资料云库资料列表
    public PageResult selectDataList(Integer currentPage,Integer pageSize,Integer categoryId) {
        PageHelper.startPage(currentPage,pageSize);
        Page<DataCloudLibrary> dataCloudLibraries = dataCloudLibraryMapper.selectDataList(categoryId);
        return new PageResult(dataCloudLibraries.getTotal(),dataCloudLibraries.getResult());
    }


    //分页查询资料云库搜索结果
    public PageResult searchDataCloud(String search,Integer currentPage,Integer pageSize){
        PageHelper.startPage(currentPage,pageSize);
        Page<DataCloudLibrary> dataCloudLibraries = dataCloudLibraryMapper.searchDataCloud(search);
        return new PageResult(dataCloudLibraries.getTotal(),dataCloudLibraries);
    }

    //查询资料云库目录列表
    public List<DataCloudLibraryCategory> dataCategories(){
        return dataCloudLibraryCategoryMapper.dataCategories();
    }

    public DataCloudLibrary selectByPrimaryKey(Integer id){
        return dataCloudLibraryMapper.selectByPrimaryKey(id);
    }

    //修改资料云库阅读次数
    public int updateDataCloud(DataCloudLibrary dataCloudLibrary){
        return dataCloudLibraryMapper.updateDataCloud(dataCloudLibrary);
    }

}
